{% extends "base.html" %}
{% load common_filters %}
{% load static %}
{% load crispy_forms_tags %}

{% block title %}
    Teacher Dashboard | {{ block.super }}
{% endblock title %}

{% block stylesheets %}
    {{ block.super }}
    <!-- Custom styles for this template -->
    <link href="{% static "laioffer/css/dashboard.css" %}" rel="stylesheet">
    <link href="{% static "hljs/default.min.css" %}" rel="stylesheet">
    <script type="text/javascript" src="{% static "hljs/highlight.min.js" %}"></script>
{% endblock stylesheets %}

{% block content %}

    <div class="container-fluid">
      <div class="row">

        {% include "_sidebar.html" %}

        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
          <h1 class="page-header">Teacher Dashboard</h1>

          {% include "_message.html" %}

          <h2 class="sub-header">{{ view.section_title }}</h2>

            {% with course=module.course %}
                <div class="contents">
                    <h3>Syllabus</h3>
                    <ul id="modules">
                    {% for m in course.modules.all %}
                        <li data-id="{{ m.id }}" {% if m == module %}class="selected"{% endif %}>
                            <a href="{% url "course:list_modules" m.id %}">
                                {{ m.title }}
                            </a>
                        </li>
                    {% empty %}
                        <li>No modules yet.</li>
                    {% endfor %}
                    </ul>
                    <p><a href="{% url "course:update_modules" course.id %}">Update modules</a></p>
                </div>
                <div class="module">
                    <div id="module-contents">
                        {% if view.is_exam %}
                            <form action="{% url "course:list_modules" module.id %}" method="post">{% csrf_token %}
                            {{ exam_form|crispy }}
                            <input type="submit" value="Update">
                            </form>
                        {% endif %}

                        {% for content in module.contents.all %}
                        <div data-id="{{ content.id }}">
                            {% with item=content.item %}
                                <b>answer time: {{ item.minutes }} mins</b>
                                {% autoescape off %}
                                    {{ item.formatted_markdown }}
                                {% endautoescape %}
                                <form action="{% url "course:delete_content" content.id %}" method="post">
                                    <a href="{% url "course:update_content" module.id item|model_name item.id %}" role="button" class="btn btn-primary">Edit</a>
                                    <input type="submit" value="Delete">
                                    {% csrf_token %}
                                </form>
                            {% endwith %}
                        </div>
                        {% empty %}
                            <p>This module has no contents yet.</p>
                        {% endfor %}
                    </div>

                    {% if not module.contents.all %}
                    <hr>
                    <h3>Add new content:</h3>
                    <ul class="content-types">
                        <li><a href="{% url "course:create_content" module.id "text" %}">Lecture</a></li>
                        <li><a href="{% url "course:create_content" module.id "problem" %}">Problem</a></li>
                    <ul>
                    {% elif view.is_exam %}
                    <hr>
                    <a role="button" class="btn btn-success btn-large" href="{% url "course:create_content" module.id "problem" %}">Add another problem</a></li>
                    {% endif %}

                </div>
            {% endwith %}

        </div> <!-- /main -->
      </div> <!-- /row -->
    </div> <!-- /container -->

    <script type="text/javascript">
        hljs.initHighlightingOnLoad();
    </script>

{% endblock content %}
